package com.ruoyi.web.controller.main;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.InsuredPersons;
import com.ruoyi.system.service.IInsuredPersonsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ReimbursementRecords;
import com.ruoyi.system.service.IReimbursementRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 参保人员-医保报销记录Controller
 * 
 * @author ruoyi
 * @date 2025-04-13
 */
@Api("参保人员-医保报销记录")
@RestController
@RequestMapping("/system/reimbursementRecords")
public class ReimbursementRecordsController extends BaseController
{
    @Autowired
    private IReimbursementRecordsService reimbursementRecordsService;

    @Autowired
    private IInsuredPersonsService insuredPersonsService;

    /**
     * 查询参保人员-医保报销记录列表
     */
//    @PreAuthorize("@ss.hasPermi('system:records:list')")
    @GetMapping("/list")
    @ApiOperation("查询参保人员-医保报销记录列表")
    public TableDataInfo list(ReimbursementRecords reimbursementRecords)
    {
        startPage();
        List<ReimbursementRecords> list = reimbursementRecordsService.selectReimbursementRecordsList(reimbursementRecords);
        if(CollectionUtils.isNotEmpty(list)){
            list = list.stream().map(item -> {
                InsuredPersons insuredPersons = insuredPersonsService.selectInsuredPersonsById(item.getInsuredPersonD());
                if(ObjectUtils.isNotEmpty(insuredPersons)){
                    item.setInsuredPersons(insuredPersons);
                }
                return item;
            }).collect(Collectors.toList());
        }
        return getDataTable(list);
    }


    /**
     * 获取参保人员-医保报销记录详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:records:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取参保人员-医保报销记录详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(reimbursementRecordsService.selectReimbursementRecordsById(id));
    }

    /**
     * 新增参保人员-医保报销记录
     */
//    @PreAuthorize("@ss.hasPermi('system:records:add')")
    @Log(title = "参保人员-医保报销记录", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增参保人员-医保报销记录")
    public AjaxResult add(@RequestBody ReimbursementRecords reimbursementRecords)
    {
        return toAjax(reimbursementRecordsService.insertReimbursementRecords(reimbursementRecords));
    }

    /**
     * 修改参保人员-医保报销记录
     */
//    @PreAuthorize("@ss.hasPermi('system:records:edit')")
    @Log(title = "参保人员-医保报销记录", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改参保人员-医保报销记录")
    public AjaxResult edit(@RequestBody ReimbursementRecords reimbursementRecords)
    {
        return toAjax(reimbursementRecordsService.updateReimbursementRecords(reimbursementRecords));
    }

    /**
     * 删除参保人员-医保报销记录
     */
//    @PreAuthorize("@ss.hasPermi('system:records:remove')")
    @Log(title = "参保人员-医保报销记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除参保人员-医保报销记录")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(reimbursementRecordsService.deleteReimbursementRecordsByIds(ids));
    }
}
